1218
class Solution {
    public int longestSubsequence(int[] arr, int difference) {
        MapInteger, Integer map = new TreeMap();
        int len = arr.length;
        int[] dp = new int[len];
        Arrays.fill(dp, 1);
        int max = 1;
        for (int i = 0; i  len; i++) {
            dp[i] += map.getOrDefault(arr[i]-difference, 0);
            map.put(arr[i], dp[i]);
            max = Math.max(dp[i], max);
        }
        return max;
    }
}